//
//  QRCodeCreateViewController.swift
//  CXSwiftWB
//
//  Created by meidaeriOS on 2017/5/27.
//  Copyright © 2017年 meidaer. All rights reserved.
//

import UIKit

class QRCodeCreateViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 创建滤镜
        let filter = CIFilter(name: "CIQRCodeGenerator")
        // 还原滤镜默认属性
        filter?.setDefaults()
        filter?.setValue("胡桃健康".data(using: String.Encoding.utf8), forKeyPath: "InputMessage")
        // 从滤镜中取出生成好的二维码图片
        guard  let ciImage = filter?.outputImage else {
            return
        }
        
//        fileprivate func  createNonInterpolateUIImageFormCIImage(_ image: CIImage, size: CGFloat) -> UIImage {
//            let extent: CGRect = image.extent.integral
//            let scale: CGFloat = min(size / extent.width, size / extent.height)
//            
//            // 1.创建bitmap;
//            let width = extent.width * scale
//            let height = extent.height * scale
//            
//            let cs: CGColorSpace = CGColorSpaceCreateDeviceGray()
//            let bitmapRef = CGContext.init(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: cs, bitmapInfo: 0)!
//            let context = CIContext(options: nil)
//            let bitmapImage: CGImage = context.createCGImage(image, from: extent)
//            CGContext.setinter
//            
//            bitmapRef.scaleBy(x: scale, y: scale)
//            bitmapRef.draw(<#T##image: CGImage##CGImage#>, in: <#T##CGRect#>)
//        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
